package com.taotao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.po.TbContent;
import com.taotao.pojo.EasyUIDataGridResult;
import com.taotao.pojo.TaotaoResult;
import com.taotao.service.ContentService;
import com.taotao.util.HttpClientUtil;

@Controller
@RequestMapping("/content")
public class ContentController {

	@Autowired
	private ContentService contentService;
	
	@Value("${REST_BASE_URL}")
	private String REST_BASE_URL;
	
	@Value("${SYNC_CONTENT_URL}")
	private String SYNC_CONTENT_URL;
	
	@RequestMapping("/query/list")
	@ResponseBody
	public EasyUIDataGridResult getContentListByCatId(Long categoryId,Integer page,Integer rows)
	{
		EasyUIDataGridResult result = contentService.getContentListByCatId(categoryId, page, rows);
		return result;		
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public TaotaoResult saveContent(TbContent content)
	{
		TaotaoResult result = contentService.addContent(content);
		// 同步内容缓存 不要写在Service层 Service层的方法都做了事务控制,如果发生异常Redis不能回滚
		// content 中有父分类
		HttpClientUtil.doGet(REST_BASE_URL+SYNC_CONTENT_URL+content.getCategoryId());
		return result;		
	}
}
